<template>
	<view class="QrSite">
		<view class="location"  @click="Golocation()">
			<span v-if="locationList == ''">添加收货地址</span>
			<span v-else v-for="(item,index) in locationList">
				<span v-if="item.isDefault == 1">
					{{item.provinceCityDistrict}}
				</span>
			</span>
		</view>
		<view class="Goods_show">
			<view class="Goods_title">
				{{GoodsList.businessName}}
			</view>
			<view class="Goods_info">
				<view class="Goods_info_image">
					<image :src="GoodsList.image"></image>
				</view>
				<view class="Goods_info_public">
					<view class="Goods_info_title">
						<view class="">
							{{GoodsList.storeName}}
						</view>
						<view class="">
							￥{{GoodsList.processingFee}}
						</view>
					</view>
					<view class="Goods_info_number">
						×{{GoodsList.cartNum}}
					</view>
				</view>

			</view>
			<view class="location_info">
				<span>配送方式</span>
				<span>快递接收</span>
			</view>
			<view class="Goods_word">
				<view class="Goods_word_title">
					<view>买家留言</view>
					<textarea v-model="status" placeholder="可以填写与卖家达成的协议"></textarea>
				</view>
			</view>
		</view>
		<view class="Goods_xx">
			<view>共计{{number}}件商品，小计：</view><span>￥{{Xprice}}.00</span>
		</view>
		<view class="Goods_Dxx">
			<view class="Goods_Dxx_price">
				<view>
					商品总金额
				</view>
				<view>
					￥{{Dprice}}
				</view>
			</view>
			<view class="Goods_Dxx_price">
				<view>
					消耗积分
				</view>
				<view>
					{{GoodsList.commodityPoints}}
				</view>
			</view>
			<view class="Goods_location">
				<view>运费</view>
				<view>￥{{postAge}}.00</view>
			</view>
		</view>
		<view class="Boottom_button">
			<view class="B_title">
				合计金额:￥<span>{{Sprice}}.00</span>
			</view>
			<view class="B_button">
				<u-button type="success" shape="circle" text="确认支付" @click="GetPay()"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				GoodsList: [],
				number: '',
				Xprice: 0,
				Dprice: 0,
				Sprice:0,
				postAge: 0,
				locationList: [],
				status:'',
				cateId:'',
				locationId:'',
				ShopPid:'',
				shopNum:'',
				commodityPoints:'',
				processingFee:''
			}
		},
		methods: {
			GetPay(){
				// #ifdef H5
				let orderSrc = 1
				// #endif
				// #ifdef MP-WEIXIN
				let orderSrc = 2
				// #endif
				// #ifdef APP-PLUS
				let orderSrc = 3
				// #endif
				if(this.locationId === ''){
					uni.showToast({
						title:'收货地址不能为空',
						icon:'error'
					})
				}else{
					console.log(this.GoodsList)
					this.$http({
						url:'/crmOrder/insCrmOrder',
						data:{
							deliveryStatus:'1',
							deliverMoney:this.postAge,
							totalAmount:this.Dprice,
							amount:this.Sprice,
							orderSrc,
							harvestAddressId:this.locationId,
							remark:this.status,
							id:this.ShopPid,
							num:this.shopNum,
							orderType:1,
							commodityPoints:this.commodityPoints,
							processingFee:this.processingFee
						}
					}).then(res=>{
						if(res.data.code === 200){
							uni.navigateTo({
								url:'/pages/bayPays/bayPays?id='+res.data.data.orderNo+'&price='+this.Sprice +'&jf='+this.commodityPoints
							})
						}
					})
				}
			},
			Golocation(){
				uni.navigateTo({
					url:'/pages/locationGo/locationGo'
				})
			},
			SearchLocation() {
				this.$http({
					url: '/crmUserAddress/selCrmUserAddress'
				}).then(res => {
					this.locationList = res.data.data
					res.data.data.map(item=>{
						if(item.isDefault == 1){
							this.locationId = item.id
						}
					})
					
				})
			},
			SearchGoods(id,num) {
				this.$http({
					url:'/crmOrder/pointSettlement',
					data:{
						pid:id,
						num:num
					}
				}).then(res => {
					console.log(res.data.data)
					this.GoodsList = res.data.data
					this.processingFee = this.GoodsList.processingFee
					this.commodityPoints = this.GoodsList.commodityPoints
					if (this.GoodsList != '') {
						this.number = this.GoodsList.length
					}
						this.Dprice = this.GoodsList.processingFee
						this.postAge = this.postAge + this.GoodsList.postage
						this.Xprice = this.GoodsList.processingFee
					
					this.Sprice = this.postAge + this.Dprice
					this.SearchLocation()
				})
			}
		},
		onLoad(option) {
			console.log(option)
			this.SearchGoods(option.pid,option.num)
			this.ShopPid = option.pid
			this.shopNum = option.num
			this.cateId = option.pid
		},
		onShow() {
			this.SearchLocation()
		}
	}
</script>

<style>
	@import './index.css';
</style>
